import { create_ListenEvent_mana } from '../../../../../../global/element/Event/listenEvent_mana';
import { normalizeContainer } from '../../../../../../global/element/Func';
import { getRadioCheckedNode } from '../../../../../../global/element/Func/getRadioCheckedNode';
import { seekElementList_name } from '../../../../../../global/Func/uniFunc/Func';
import { setToCurEl_keyVal_node } from '../../Func/setToCurEl_keyVal_node';
import {
  unf_style_keyVal,
  unf_style_radio_name,
} from './DataDefine/sourceData';

/**
 * 浮动元素 style 样式 主体 id
 */
const unf_style_keyVal_o_id = 'unf_keyVal_o$style';

/**
 * 浮动元素 style 样式 主体
 * @type {HTMLElement}
 */
let unf_style_keyVal_o_el;

let eventM = create_ListenEvent_mana('uni_ns_form_style');

function init_unf_style() {
  unf_style_keyVal_o_el = normalizeContainer(unf_style_keyVal_o_id);

  eventM.addEventListen(unf_style_keyVal_o_el, 'click', targetEl_click);
}

/**
 * style radio 选择 点击
 * @param {MouseEvent} event
 */
function targetEl_click(event) {
  // 因为 label 会 再次 点击 radio 元素
  if (event.target.tagName == 'LABEL') {
    return;
  }

  /**
   * redio name nodeList
   */
  let nameNodeList = seekElementList_name(unf_style_radio_name);

  let checkedNode = getRadioCheckedNode(nameNodeList);

  let val = checkedNode.value;

  setToCurEl_keyVal_node(unf_style_keyVal, val);
}

export { init_unf_style };
